<?php
function curl($url, $type = 'GET', $data = '', $Async = true, $oTime=800)
{
    //$Asynchronous：异步请求
    $ch = curl_init();
    $data = http_build_query($data);

    if ($Async) {
        curl_setopt($ch, CURLOPT_NOSIGNAL, true);//注意，毫秒超时一定要设置这个
        curl_setopt($ch, CURLOPT_TIMEOUT_MS, $oTime);//超时毫秒，小于500时不稳定，测试在600以上可以
    }

    // post
    if (strcasecmp($type, 'post') === 0){
        curl_setopt($ch, CURLOPT_POST, true);
    }

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);


    $info = curl_exec($ch);
    if (curl_errno($ch)) {
        return 'Errno' . curl_error($ch);
    }

    curl_close($ch);
    $temp = json_decode($info, true);
    if ($temp){
        return $temp;
    }
    return $info;
}